package com.ruoyi.aiexperiments.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.aiexperiments.domain.TestEvaluation;
import com.ruoyi.aiexperiments.service.ITestEvaluationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 测试数据评估Controller
 * 
 * @author czj
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/evaluation")
public class TestEvaluationController extends BaseController
{
    @Autowired
    private ITestEvaluationService testEvaluationService;

    /**
     * 查询测试数据评估列表
     */
    @RequiresPermissions("aiexperiments:evaluation:list")
    @GetMapping("/list")
    public TableDataInfo list(TestEvaluation testEvaluation)
    {
        testEvaluation.setDeleteFlag(0);
        startPage();
        List<TestEvaluation> list = testEvaluationService.selectTestEvaluationList(testEvaluation);
        return getDataTable(list);
    }

    /**
     * 导出测试数据评估列表
     */
    @RequiresPermissions("aiexperiments:evaluation:export")
    @Log(title = "测试数据评估", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestEvaluation testEvaluation)
    {
        List<TestEvaluation> list = testEvaluationService.selectTestEvaluationList(testEvaluation);
        ExcelUtil<TestEvaluation> util = new ExcelUtil<TestEvaluation>(TestEvaluation.class);
        util.exportExcel(response, list, "测试数据评估数据");
    }

    /**
     * 获取测试数据评估详细信息
     */
    @RequiresPermissions("aiexperiments:evaluation:query")
    @GetMapping(value = "/{evaluationId}")
    public AjaxResult getInfo(@PathVariable("evaluationId") Long evaluationId)
    {
        return success(testEvaluationService.selectTestEvaluationByEvaluationId(evaluationId));
    }

    /**
     * 新增测试数据评估
     */
    @RequiresPermissions("aiexperiments:evaluation:add")
    @Log(title = "测试数据评估", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestEvaluation testEvaluation)
    {
        testEvaluation.setCreatedBy(SecurityUtils.getUsername());
        testEvaluation.setCreatedAt(new Date());
        return toAjax(testEvaluationService.insertTestEvaluation(testEvaluation));
    }

    /**
     * 修改测试数据评估
     */
    @RequiresPermissions("aiexperiments:evaluation:edit")
    @Log(title = "测试数据评估", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestEvaluation testEvaluation)
    {
        testEvaluation.setUpdatedBy(SecurityUtils.getUsername());
        testEvaluation.setUpdatedAt(new Date());
        return toAjax(testEvaluationService.updateTestEvaluation(testEvaluation));
    }

    /**
     * 删除测试数据评估
     */
    @RequiresPermissions("aiexperiments:evaluation:remove")
    @Log(title = "测试数据评估", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evaluationIds}")
    public AjaxResult remove(@PathVariable Long[] evaluationIds)
    {
        for (Long evaluationId : evaluationIds) {
            TestEvaluation testEvaluation = testEvaluationService.selectTestEvaluationByEvaluationId(evaluationId);
            if (testEvaluation == null) {
                return error("测试数据评估不存在");
            }
            testEvaluation.setDeletedBy(SecurityUtils.getUsername());
            testEvaluation.setDeletedAt(new Date());
            testEvaluation.setDeleteFlag(1);
            testEvaluationService.updateTestEvaluation(testEvaluation);
        }
        return toAjax(true);
    }
}
